//
//  ViewController.m
//  Music
//
//  Created by ExcuseMe on 17/2/23.
//  Copyright © 2017年 suyubo. All rights reserved.
//

#import "ViewController.h"
//1.添加头文件
#import <AVFoundation/AVFoundation.h>
#import "SecondViewController.h"
@interface ViewController ()
//2.创建音乐播放器对象
@property(nonatomic,strong)AVAudioPlayer *myPlayer;
//按钮
@property(nonatomic,strong)UIButton *button;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //3.音乐的播放
    //3.1 初始化播放器
    NSString *musicName=[[NSBundle mainBundle]pathForResource:@"王妃.mp3" ofType:nil];
    NSURL *musicUrl=[NSURL fileURLWithPath:musicName];
    _myPlayer=[[AVAudioPlayer alloc]initWithContentsOfURL:musicUrl error:nil];
    //3.2 播放器的基本设置
    _myPlayer.numberOfLoops=0;//无限循环
    [_myPlayer prepareToPlay];
    //3.3 进行播放
    [_myPlayer play];
    _button=[[UIButton alloc]initWithFrame:CGRectMake(100, 300, 100, 60)];
    [_button setTitle:@"exchange" forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(cliked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_button];
    self.view.backgroundColor=[UIColor greenColor];
}
-(void)cliked{
    SecondViewController *secView=[[SecondViewController alloc]init];
    [self presentViewController:secView animated:YES completion:nil];
    [_myPlayer pause];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
